<?php

namespace Tbf\Bundle\PackageBundle\ClassGenerator;
use CG\Generator\PhpClass as BasePhpClass;
use CG\Generator\PhpMethod;
use CG\Generator\PhpParameter;
use Tbf\Bundle\PackageBundle\Annotation\Annotation;
use Tbf\Bundle\PackageBundle\Annotation\AnnotationCollection;

class EntityDefine extends BasePhpClass
{
    protected $file_path;
    protected $annotation_list;
    public function __construct($name = null)
    {
        $this->annotation_list = new AnnotationCollection();
        parent::__construct($name);
    }
    public function addAnnotation(Annotation $annotation)
    {
        $this->annotation_list->addAnnotation($annotation);

        return $this;
    }
    public function getDocblock()
    {
        return $this->annotation_list->getDocblock();
    }

    public function getFilePath()
    {
        return $this->file_path;
    }
    public function setFilePath($file_path)
    {
        $this->file_path = $file_path;

        return $this;
    }
    public function setName($name)
    {
        $name = ltrim($name,'\\');

        return parent::setName($name);
    }
    /**
     * @return EntityDefine
     */
    public static function create($name=null)
    {
        $name = ltrim($name,'\\');

        return new static($name);
    }
    public function addGetterSetterMethod()
    {
        foreach ($this->getProperties() as $property) {
            /** @var \Tbf\Bundle\PackageBundle\ClassGenerator\PhpProperty $property */
            $name = $property->getName();
            $this->setMethod(
                PhpMethod::create('get'.ucfirst($name))
                    ->setVisibility('public')
                    ->setBody('return $this->'.$name.';')
            )
            ->setMethod(
                PhpMethod::create('set'.ucfirst($name))
                    ->setVisibility('public')
                    ->setParameters(array(PhpParameter::create('value')))
                    ->setBody('$this->'.$name.' = $value;')
            );
        }

        return $this;
    }
}
